project(common-audio)

file(GLOB common_audio_sources
        ${CMAKE_CURRENT_SOURCE_DIR}/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/resampler/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/resampler/include/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/signal_processing/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/signal_processing/include/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/vad/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/vad/include/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)

list(APPEND common_audio_sources
        "audio_converter.cc"
        "audio_util.cc"
        "channel_buffer.cc"
        "fir_filter_c.cc"
        "fir_filter_factory.cc"
        "real_fourier.cc"
        "real_fourier_ooura.cc"
        "resampler/push_resampler.cc"
        "resampler/push_sinc_resampler.cc"
        "resampler/resampler.cc"
        "resampler/sinc_resampler.cc"
        "resampler/sinusoidal_linear_chirp_source.cc"
        "ring_buffer.c"
        "signal_processing/auto_correlation.c"
        "signal_processing/auto_corr_to_refl_coef.c"
        "signal_processing/complex_bit_reverse.c"
        "signal_processing/complex_fft.c"
        "signal_processing/copy_set_operations.c"
        "signal_processing/cross_correlation.c"
        "signal_processing/division_operations.c"
        "signal_processing/dot_product_with_scale.cc"
        "signal_processing/downsample_fast.c"
        "signal_processing/filter_ar.c"
        "signal_processing/filter_ar_fast_q12.c"
        "signal_processing/energy.c"
        "signal_processing/filter_ma_fast_q12.c"
        "signal_processing/get_hanning_window.c"
        "signal_processing/get_scaling_square.c"
        "signal_processing/ilbc_specific_functions.c"
        "signal_processing/levinson_durbin.c"
        "signal_processing/lpc_to_refl_coef.c"
        "signal_processing/min_max_operations.c"
        "signal_processing/randomization_functions.c"
        "signal_processing/real_fft.c"
        "signal_processing/refl_coef_to_lpc.c"
        "signal_processing/resample_48khz.c"
        "signal_processing/resample_by_2.c"
        "signal_processing/resample_by_2_internal.c"
        "signal_processing/resample.c"
        "signal_processing/resample_fractional.c"
        "signal_processing/spl_init.c"
        "signal_processing/spl_inl.c"
        "signal_processing/splitting_filter.c"
        "signal_processing/spl_sqrt.c"
        "signal_processing/sqrt_of_one_minus_x_squared.c"
        "signal_processing/vector_scaling_operations.c"
        "smoothing_filter.cc"
        "third_party/ooura/fft_size_128/ooura_fft.cc"
        "third_party/ooura/fft_size_256/fft4g.cc"
        "third_party/spl_sqrt_floor/spl_sqrt_floor.c"
        "vad/vad.cc"
        "vad/vad_core.c"
        "vad/vad_filterbank.c"
        "vad/vad_gmm.c"
        "vad/vad_sp.c"
        "vad/webrtc_vad.c"
        "wav_file.cc"
        "wav_header.cc"
        "window_generator.cc"
        )

## X86 or X86_64
if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
    list(APPEND common_audio_sources
        # common_audio_sse2
        "fir_filter_sse.cc"
        "resampler/sinc_resampler_sse.cc"
        "third_party/ooura/fft_size_128/ooura_fft_sse2.cc"
        # common_audio_avx
        "fir_filter_avx2.cc"
        "resampler/sinc_resampler_avx2.cc"
    )
endif ()

add_library(${PROJECT_NAME} ${LIB_TYPE} ${common_audio_sources})

target_link_libraries(${PROJECT_NAME} PUBLIC rtc-base)